Skip to content

Conversation

@amychisholm03
Copy link
Contributor

@amychisholm03 amychisholm03 commented Nov 12, 2025

Description

This PR builds off the new sampling architecture defined by #3527.

This PR adds another Sampler that is akin to OpenTelemetry's TraceIdRatioBasedSampler.

How to Test

Cross-agent tests are re-synced! The new tests uncovered some missing pieces with our sampling logic, outside of ratio-based sampling, which this PR solves.

npm run unit
npm run integration

Related Issues

Closes #3387 and closes #3480

@amychisholm03 amychisholm03 marked this pull request as draft November 12, 2025 15:34
@amychisholm03 amychisholm03 changed the title feat: Trace feat: TraceIdRatioBasedSampler Nov 12, 2025
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 97.89474% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.64%. Comparing base (ad63441) to head (e687350).

Files with missing lines Patch % Lines
lib/samplers/ratio-based-sampler.js 97.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3501      +/-   ##
==========================================
- Coverage   97.77%   97.64%   -0.13%     
==========================================
  Files         426      427       +1     
  Lines       55918    56012      +94     
  Branches        1        1              
==========================================
+ Hits        54672    54695      +23     
- Misses       1246     1317      +71     
Flag Coverage Δ
integration-tests-cjs-20.x 74.00% <94.73%> (+0.07%) ⬆️
integration-tests-cjs-22.x 74.04% <94.73%> (+0.07%) ⬆️
integration-tests-cjs-24.x 74.79% <94.73%> (+0.07%) ⬆️
integration-tests-esm-20.x 52.65% <56.84%> (+<0.01%) ⬆️
integration-tests-esm-22.x 52.70% <56.84%> (+<0.01%) ⬆️
integration-tests-esm-24.x 53.90% <56.84%> (+<0.01%) ⬆️
unit-tests-20.x 88.71% <95.78%> (+<0.01%) ⬆️
unit-tests-22.x 88.75% <95.78%> (+0.01%) ⬆️
unit-tests-24.x 88.76% <95.78%> (+0.01%) ⬆️
versioned-tests-20.x 81.02% <56.84%> (-0.36%) ⬇️
versioned-tests-22.x 81.03% <56.84%> (-0.36%) ⬇️
versioned-tests-24.x 80.96% <56.84%> (-0.37%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch 10 times, most recently from 531c86e to 0356e15 Compare November 17, 2025 19:53
@amychisholm03 amychisholm03 changed the title feat: TraceIdRatioBasedSampler feat: TraceIdRatioBasedSampler and other sampling fixes Nov 18, 2025
@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch 2 times, most recently from 88dfa7a to f2b2208 Compare November 18, 2025 02:27
@amychisholm03 amychisholm03 marked this pull request as ready for review November 18, 2025 02:32
@bizob2828 bizob2828 self-assigned this Nov 18, 2025
Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't fully reviewed but I have some concerns with our approach, especially when you layer on partial granularity/full granularity tracing

applySamplingDecision(transaction) {
if (!transaction) return
// eslint-disable-next-line sonarjs/pseudo-random
const initPriority = Math.random()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the sample logic as the adaptive, it's just that it calls its shouldSample method. Feels like this should be in the default Sampler class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that was my first thought too. However the parameters passed into shouldSample differ, so there's no real repeated logic except for the priority calc and truncation.

}

// Is it TraceIdRatioBased?
const ratioBasedSampler = samplerDefinition?.trace_id_ratio_based
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic should live in the config. we shouldn't have to check if it's a valid ratio here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we shouldn't but it's there as kind of a fail safe

@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch 2 times, most recently from 0942856 to c98bd79 Compare November 18, 2025 20:28
@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch 2 times, most recently from 63f0379 to 4bb1061 Compare November 19, 2025 15:14
@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch from 04c45d1 to 5ed77ee Compare November 19, 2025 19:19
@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch from 5ed77ee to 5c0285f Compare November 20, 2025 22:53
@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch from 5c0285f to 3dc878c Compare November 20, 2025 23:00
@amychisholm03 amychisholm03 changed the title feat: TraceIdRatioBasedSampler and other sampling fixes feat: TraceIdRatioBasedSampler and re-sync cross agent tests Nov 20, 2025
@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch from ee10b81 to d41756c Compare November 20, 2025 23:57
@amychisholm03 amychisholm03 force-pushed the NR-3387/ratio-based-sampler branch from 8e32efe to e687350 Compare November 21, 2025 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs PR Review

Development

Successfully merging this pull request may close these issues.

Resync Cross agent tests Add ratio based sampler

2 participants